export default {
  data() {
    return {
      list: [],
      today: '',
    };
  },
  onLoad(e) {
    let date = new Date();
    let year = date.getFullYear();
    let month = date.getMonth() + 1;
    let day = date.getDate();
    this.today = year + '年' + month + '月' + day + '日';
    this.getTodayList()
  },
  methods: {
    getTodayList() {
      //获取当前时间月日
      let date = new Date();
      let month = date.getMonth() + 1;
      let day = date.getDate();
      let today = month + '/' + day;
      let historicalEvent = uni.getStorageSync('historicalEvent');
      let setDay = uni.getStorageSync('today');
      if (setDay == today && historicalEvent) {
        this.list = historicalEvent;
        return;
      }
      uni.request({
        url: 'http://v.juhe.cn/todayOnhistory/queryEvent.php',
        data: {
          key: '95ec04aa7f9d5668133fbb8f688ccf47',
          date: today
        },
        header: {
          'Content-Type': 'application/x-www-form-urlencoded',
        },
        method: 'GET',
        success: (res) => {
          if (res.statusCode == 200) {
            let list = res.data.result;
            console.log(list,'list');
            list.forEach((item, index) => {
              item.date = item.date.split('年')[0] + '年';
            })
            this.list = list;
            uni.setStorageSync('historicalEvent', list)
            uni.setStorageSync('today', today)
          }
        },
        fail: (error) => { }
      })
    },
  },
}